package com.example.clienteencript;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MenuServiciosActivity extends Activity {	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actitity_menu);

		Button btnRegistrarAdministrador=(Button)findViewById(R.id.botonRegistrarAdministrador);
		Button btnEncriptarTexto=(Button)findViewById(R.id.botonEncriptarTexto);
		Button btnDesencriptarTexto=(Button)findViewById(R.id.botonDesencriptarTexto);
		Button btnCerrarSesion = (Button)findViewById(R.id.botonCerrarSesion);

		Bundle bundle = getIntent().getExtras();
		final String token = bundle.getString("token");

		btnRegistrarAdministrador.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String mensaje = android.controller.EncriptController.validarLogin(token);
				if(mensaje.equals("Invalido")){
					Intent t = new Intent(MenuServiciosActivity.this, MainActivity.class);
					String TokenIsDead = null;
					t.putExtra("token", TokenIsDead);
					startActivity(t);
					finish();     
				} else {
					System.out.println("Registrar Administrador");
					Intent t = new Intent(MenuServiciosActivity.this, RegistroAdministradorActivity.class);
					t.putExtra("token", token);
					startActivity(t);
					finish();    
				}

			}});

		btnEncriptarTexto.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String mensaje = android.controller.EncriptController .validarLogin(token);
				if(mensaje.equals("Invalido")){
					System.out.println("Token invalido en desencriptar");
					Intent t = new Intent(MenuServiciosActivity.this, MainActivity.class);
					String TokenIsDead = null;
					t.putExtra("token", TokenIsDead);
					startActivity(t);
					finish();     
				} else {
					System.out.println("Encriptar Texto");
					Intent t = new Intent(MenuServiciosActivity.this, EncriptarTextoActivity.class);
					t.putExtra("token", token);
					startActivity(t);
					finish();     
				}
			}});

		btnDesencriptarTexto.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String mensaje = android.controller.EncriptController .validarLogin(token);
				if(mensaje.equals("Invalido")){
					Intent t = new Intent(MenuServiciosActivity.this, MainActivity.class);
					String TokenIsDead = null;
					t.putExtra("token", TokenIsDead);
					startActivity(t);
					finish();     
				} else {
					System.out.println("Desencriptar Texto");
					Intent t = new Intent(MenuServiciosActivity.this, DesencriptarTextoActivity.class);
					t.putExtra("token", token);
					startActivity(t);
					finish();        
				}
			}});

	

		btnCerrarSesion.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent t = new Intent(MenuServiciosActivity.this, MainActivity.class);
				String TokenIsDead = null;
				t.putExtra("token", TokenIsDead);
				startActivity(t);
				finish();     
			}});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_servicios, menu);
		return true;
	}

}
